package com.example.quanlithuchi;

import Adapter.MainAdapter;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class MainMenus extends Activity {

	MainAdapter adapter; Context context=this;
	ListView listView;
	AlertDialog dialog;Intent intent;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_menus);
		//String[]strings=getResources().getStringArray(R.array.)
		String[] arraStrings=getResources().getStringArray(R.array.VanhungMain);
		adapter=new MainAdapter(context, R.layout.main_item, arraStrings);
		listView=(ListView) findViewById(R.id.ListItemMenu);
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View view, int posittion,
					long arg3) {
				
				// TODO Auto-generated method stub
				switch (posittion) {
				case 0:
				{
					intent=new Intent(context, QuanLiNoActivity.class);
					
				}
					break;
				case 1:
				{
					intent=new Intent(context, Thu_Chi_Activity.class);
				}
					break;
				case 2:
				{
					CreateDialog();
				}
					break;
					

				
				}
				if (intent!=null) {
					
					startActivity(intent);
				}
				
				
			}
		});
		listView.setAdapter(adapter);
		
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main_menus, menu);
		return true;
	}
	void CreateDialog()
	{
		AlertDialog.Builder builder=new AlertDialog.Builder(context);
		builder.setTitle("chọn tiêu chí thống kê");
		View view=getLayoutInflater().inflate(R.layout.dialog_thongke, null);
		builder.setView(view);
		Button btnthu=(Button) view.findViewById(R.id.btnthongke_thu);
		btnthu.setOnClickListener(onbuttonthongkeClickListener);
		Button btnchi=(Button) view.findViewById(R.id.btnthongke_chi);
		btnchi.setOnClickListener(onbuttonthongkeClickListener);
		Button btnnoButton=(Button) view.findViewById(R.id.btnthongke_no);
		btnnoButton.setOnClickListener(onbuttonthongkeClickListener);
		  dialog=builder.create();
		dialog.show();
	}
	OnClickListener onbuttonthongkeClickListener=new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			dialog.dismiss();
			switch (v.getId()) {
			case R.id.btnthongke_thu:
			{
			      intent=new Intent(context, ThongkeActivity.class);
			      intent.putExtra("isthuchi", 0);
			      startActivity(intent);
			}
				break;
			case R.id.btnthongke_chi:
			{
				 intent=new Intent(context, ThongkeActivity.class);
			      intent.putExtra("isthuchi", 1);
			      startActivity(intent);
			}
				break;
			case R.id.btnthongke_no:
			{
				 intent=new Intent(context, ThongkeActivity.class);
			      intent.putExtra("isthuchi", -1);
			      startActivity(intent);
			}
				break;

			default:
				break;
			}
		}
	};

}
